<?php $form=$this->beginWidget('CActiveForm', array(
        'id'=>'post-reply-form',
        'enableClientValidation'=>true,
        'clientOptions'=>array(
            'validateOnSubmit' => true,
            'validateOnChange' => true,
            'afterValidate' => "js:function(form, data, hasError){
                return postReplyAfterValidate(form, data, hasError);
            }",
        ),
        'enableAjaxValidation'=>false,
        'htmlOptions' => array('class' => 'form-horizontal', 'actionType' => $this->action->id)
    )); ?>

<?php echo $form->errorSummary($model); ?>

<div class="panel panel-simple">
    <div class="panel-heading primary">
        <h3 class="panel-title"><i class="fa fa-list-alt"></i> Nội dung <span class="panel-under"></h3>
    </div>
    <div class="panel-body">
        <div class="form-group">
            <label class="col col-sm-4 control-label">Trả lời tại bài viết</label>
            <div class="col-sm-20">
                <a href="<?php echo $post->url?>"><?php echo $post->title?></a>
            </div> 
        </div>
        <?php if($postReplyReply):?>
        <div class="form-group">
            <label class="col col-sm-4 control-label">Gửi tới </label>
            <div class="col-sm-20">
                <a href="#<?php echo $post->url?>#reply_<?php echo $postReplyReply->id?>" data-toggle="popover" data-trigger="hover" data-placement="right" title="<?php echo $postReplyReply->user->name?> nói:" data-content="<?php echo Myext::word_limit(strip_tags($postReplyReply->content), 200)?>">
                    @<?php echo $postReplyReply->user->name?>
                </a>   
                <i id="reply_to_user_remove" class="fa fa-times text-danger" title="Bỏ gửi tới thành viên này" rel="tooltip" style="cursor: pointer;"></i>
            </div>
        </div>
        <?php endif?>

        <div class="form-group">
            <?php echo $form->labelEx($model,'content', array('class' => 'col col-sm-4 control-label')); ?>
            <div class="col-sm-20">
                <?php echo $form->textArea($model,'content', array('style' => 'height: 300px', 'class' => 'editor')); ?>
                <?php echo $form->hiddenField($model,'post_id'); ?>
                <?php echo $form->hiddenField($model,'reply_id'); ?>
                <?php echo $form->error($model,'content');?>
            </div>
        </div>
    </div>
</div> 

<div class="panel panel-simple">
    <div class="panel-heading success">
        <h3 class="panel-title"><i class="fa fa-picture-o"></i> Đăng ảnh <span class="panel-under"></h3>
    </div>
    <div class="panel-body">
        <?php echo $form->error($model,'image', array('style' => 'margin-left: 0px'));?> 

        <!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
        <div class="row fileupload-buttonbar" style="margin-bottom: 20px;">
            <div class="col-sm-12">
                <div class="row">
                    <div class="col-md-8 col-sm-24">
                        <span class="btn btn-success fileinput-button">
                            <span><i class="fa fa-upload"></i> Tải ảnh lên</span>
                            <input type="file" name="files[]" multiple>
                        </span> 
                    </div>
                    <div class="col-md-16 hidden-sm hidden-xs hidden-sm">
                        Hoặc kéo & thả ảnh vào đây
                    </div>
                </div>
            </div>
            <!-- The global progress information -->
            <div class="col-sm-12 fileupload-progress fade">
                <!-- The global progress bar -->
                <div class="progress progress-striped active" style="margin: 0;" role="progressbar" aria-valuemin="0" aria-valuemax="100">
                    <div class="bar progress-bar" style="width:0%;"></div>
                </div>
                <!-- The extended global progress information -->
            </div>
        </div>
        <!-- The table listing the files available for upload/download -->
        <div id="upload-grid">
            <table role="presentation" class="table table-striped table-hover table-condensed">
                <tbody class="files"></tbody>
            </table>
        </div>
    </div>
</div> 

<div class="form-group">
    <div class="col-sm-offset-10 col-sm-14">
        <button class="btn btn-primary btn-lg" type="submit">
            <?php if($model->isNewRecord):?>
                <i class="fa fa-pencil-square-o"></i> Gửi trả lời
                <?php else:?>
                <i class="fa fa-pencil-square-o"></i> Sửa trả lời
                <?php endif?>
        </button>        
    </div>
</div>
<?php $this->endWidget(); ?>

<?php $this->renderPartial('_upload_require')?>

<!--[if gte IE 8]><script src="/files/js/jquery.file.upload/js/cors/jquery.xdr-transport.js"></script><![endif]-->
<script>var post_reply_upload_url = '<?php 
    $params = array('type' => 'reply'); 
    if($model->id) $params['id'] = $model->id; 
    echo $this->createUrl('/hangve/post/upload', $params);
?>';</script>

<script type="text/javascript" src="/files/editor/tinymce4/tinymce.min.js"></script>
<script type="text/javascript" src="<?php echo $this->themeUrl?>/files/js/reply_form.js"></script> 